package leetcode.editor.cn;

import java.util.*;
import leetcode.editor.common.*;

public class InvertBinaryTree {

    //leetcode submit region begin(Prohibit modification and deletion)
    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode() {}
     *     TreeNode(int val) { this.val = val; }
     *     TreeNode(int val, TreeNode left, TreeNode right) {
     *         this.val = val;
     *         this.left = left;
     *         this.right = right;
     *     }
     * }
     */
    class Solution {
        public TreeNode invertTree(TreeNode root) {
            if(root==null){
                return root;
            }

            final TreeNode temp = root.left;
            root.left=root.right;
            root.right=temp;
            invertTree(root.left);
            invertTree(root.right);



            return root;
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)

    
    public static void main(String[] args) {
        Solution solution = new InvertBinaryTree().new Solution();
        // put your test code here
        final TreeNode treeNode = TreeNode.createRoot(new Integer[]{4, 2, 7, 1, 3, 6, 9});
        solution.invertTree(treeNode);
    }
}
